public class Solution {
    public int maxProfit(int[] prices) {
        int len = prices.length;
        if(len < 2) {
            return 0;
        }
        int min = prices[0];
        int maxV = 0;

        for(int i = 1; i < len; i++) {
            min = Math.min(prices[i], min);
            maxV = Math.max(maxV, prices[i] - min);
        }
        return maxV;
    }
}
